    // Server.java
    package edu.cmu.cs214.hw9.server;
     
    import java.net.*;
    import java.util.Hashtable;
    import java.util.LinkedList;
     
    import edu.cmu.cs214.hw9.db.SQLiteAdapter;
    import edu.cmu.cs214.hw9.db.Constants;
    import edu.cmu.cs214.hw9.db.UserData;
    /**
     * Class that starts the server(s) for facelook.  Heavily borrowed from 15-214
     * DistribLab staff code
     *
     */
    public class Server {
    	
        public static void main(String[] args){
                //open server socket(s), initialize database handler.  Database handler
                //is for facelook.db file (see SQLiteAdapter), so if we want multiple
                //databases for our multiple servers, we'd have to add more
                int counter = 0;  // ADDED FOR SHARDING: -SARAH SPOCK
                int serverPort = 1910;
               
                UserData ud = null;
                UserData[] uds = new UserData[5];
                ServerSocket[] sockets = new ServerSocket[5];
                try {
                        while (counter < Constants.NUMBER_OF_SHARDS) // ADDED FOR SHARDING- Sarah Spock
                        {
                            ud = new UserData("facelook" + counter +".db", serverPort + counter); //initialize new database accessor. EDITED: Sarah Spock
                            uds[counter] = ud;
                            counter++;
                        }
                      //  dataForShardsToHandle(); // assigns data for the shards to handle.
                } catch (Exception e1) {
                        e1.printStackTrace();
                }
               
                try {
                    int counterB = 0;
                    while (counterB < Constants.NUMBER_OF_SHARDS)
                    {
                            uds[counterB].createTables(); //create the tables  - ADDED SHARDING CAPABILITIES
                            ServerSocket socket = new ServerSocket(serverPort+counterB); //create the server socket
                            sockets[counterB] = socket;
                            counterB++;
                    }
                   
                    while(true){
                            Thread connection0 = new ServerThread(sockets[0].accept(), uds[0]);//spawn a thread to do the work
                          //  Thread connection1 = new ServerThread(sockets[1].accept(), uds[1]);
                           // Thread connection2 = new ServerThread(sockets[2].accept(), uds[2]);
                            //Thread connection3 = new ServerThread(sockets[3].accept(), uds[3]);
                            //Thread connection4 = new ServerThread(sockets[4].accept(), uds[4]);
                            connection0.start();
                            //connection1.start();
                            //connection2.start();
                            //connection3.start();
                            //connection4.start();
                        }
                } catch (Exception e){
                        e.printStackTrace();
                        System.exit(-1);
                }
        }
//        // THIS ASSIGNS THE SHARD OF USERDATA A LETTER TO HANDLE  - Handles by letter 
//        private static void dataForShardsToHandle() {
//                // int isnt perfect math so we need to assign shards with unequal letters
//                        shardHash.put(shards.get(0), "ABCDE");  // Maps the userdata item to the letters it should process.
//                        shardHash.put(shards.get(1), "FGHIJ");  // Maps the userdata item to the letters it should process.
//                        shardHash.put(shards.get(2), "KLMNO");  // Maps the userdata item to the letters it should process.
//                        shardHash.put(shards.get(3), "PQRST");  // Maps the userdata item to the letters it should process.
//                        shardHash.put(shards.get(4), "UVWXYZ");  // Maps the userdata item to the letters it should process.
//        }
//        // ADDED FOR SHARDING
//        public static LinkedList<UserData> getShards(){
//                return shards;
//        }
//        // ADDED FOR SHARDING
//        @SuppressWarnings("rawtypes")
//        public static Hashtable getShardHash(){
//                return shardHash;
//        }
//        // ADDED FOR SHARDING
//        public static LinkedList<ServerSocket> getSockets(){
//                return sockets;
//        }
    }